import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;

public class CalculatorTest {

	@Test
	public void testDivide() {
		Calculator calculator = new Calculator();
		String result = calculator.divide("10", "4");
		assertEquals("2.5",result);
	}
	
	@Test(expected=DivideByZeroException.class)
	public void testDivideByZero(){
		Calculator c  =  new Calculator();
		c.divide("4", "0");
		
	}
	
	@Test 
	public void testDivideWithPrecision(){
		Calculator c =  new Calculator();
		assertEquals("59.461", c.divide("773", "13",3));
	}

	@Test
	public void testAdd() {
		Calculator calculator = new Calculator();
		double result = calculator.add("10", "-4");
		assertEquals(6, result, 0);

	}

	@org.junit.Test
	public void testSub() {
		Calculator calculator = new Calculator();
		double result = calculator.sub("10", "4");
		assertEquals(6, result, 0);

	}

	@Test
	public void testEncodeToString() {
		Calculator test = new Calculator();
		List<Integer> list = new ArrayList<Integer>();
		list.add(2);
		list.add(5);
		assertEquals("2.5", test.encodeToString(list));

		List<Integer> list2 = new ArrayList<Integer>();
		list2.add(59);
		list2.add(4);
		list2.add(6);
		list2.add(1);
		list2.add(5);
		list2.add(4);
		assertEquals("59.46154", test.encodeToString(list2));
	}

	@Test
	public void testCountSubstractionIrrational() {
		Calculator c = new Calculator();
		List<Integer> expected = Arrays.asList(59, 4, 6, 1, 5, 3);
		assertEquals(expected, c.countSubstraction(773, 13,5));
	}

	@org.junit.Test
	public void testMult() {
		Calculator calculator = new Calculator();
		double result = calculator.mult("5", "5");
		assertEquals(25, result, 0);

	}

}
